/*
 *  Copyright 2010 Wesley Gooch, Ryan Nix, Cody Wenzel.
 *  Montana State University - Spring Semester 2010
 *  Computer Science 450 - Compilers
 *  Project: Micro-Pascal Compiler
 */
package msu.compiler.scanner.fsas;

import msu.compiler.scanner.Tokenizer;
import msu.compiler.scanner.Token;

/**
 * StateMachineFactory utilizes the Simple-Factory-Pattern to encapsulate
 * FSA generation and execution.
 * 
 * @author Wesley Gooch
 */
public class StateMachineFactory {

    private Tokenizer tokenizer;

    public StateMachineFactory(Tokenizer tokenizer) {
        this.tokenizer = tokenizer;
    }

    /**
     * The executeFSA function builds a state machine based on the given
     * FSA string type and executes that fsa against the give character.
     *
     * @param type  The type of FSA to construct
     */
    public void executeFSA(String type) {
        FSA stateMachine = null;

        if (type.equals("ColonFSA")) {
            stateMachine = new ColonFSA(tokenizer);
        } else if (type.equals("DigitFSA")) {
            stateMachine = new DigitFSA(tokenizer);
        } else if (type.equals("GreaterThanFSA")) {
            stateMachine = new GreaterThanFSA(tokenizer);
        } else if (type.equals("IdentifierFSA")) {
            stateMachine = new IdentifierFSA(tokenizer);
        } else if (type.equals("LessThanFSA")) {
            stateMachine = new LessThanFSA(tokenizer);
        } else if (type.equals("StringLiteralFSA")) {
            stateMachine = new StringLiteralFSA(tokenizer);
        }

        stateMachine.execute();
    }
}
